local sanshou = fk.CreateSkill {

  name = "joy__sanshou",

  tags = {  },

}



sanshou:addEffect(fk.DamageInflicted, {
  name = "joy__sanshou",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sanshou.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(3)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = sanshou.name,
    })
    local yes = false
    for _, id in ipairs(cards) do
      if player:getMark("joy__sanshou_"..Fk:getCardById(id):getTypeString().."-turn") == 0 then
        room:setCardEmotion(id, "judgegood")
        yes = true
      else
        room:setCardEmotion(id, "judgebad")
      end
    end
    room:delay(1000)
    room:moveCards({
      ids = cards,
      fromArea = Card.Processing,
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonJustMove,
      skillName = sanshou.name,
    })
    if yes then
      return true
    end
  end,
})
sanshou:addEffect(fk.AfterCardUseDeclared, {
  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "joy__sanshou_"..data.card:getTypeString().."-turn", 1)
  end,
})

return sanshou